package com.t2t.top.framework.support;

import com.t2t.top.framework.diamond.DiamondEnv;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentMap;

/**
 * Spring自定义PropertyPlaceholderConfigurer.
 */
public class CustomPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    protected Properties mergeProperties() throws IOException {
        // TODO: 2016/9/5 暂时未用
        Properties properties = super.mergeProperties();

        logger.info("initEnv开始");
        DiamondEnv.initEnv();
        logger.info("initEnv完成");

        Properties result = new Properties();
        ConcurrentMap<String, String> env = DiamondEnv.getEnv();
        for (String key : env.keySet()) {
            result.setProperty(key, env.get(key));
            logger.info("{}={}", key, env.get(key));
        }
        return result;
    }

}